home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turn the Power On! 3
/
Turn the Power On! HP Volume III (HP)(1995).ISO
/
copy_to_disk
< prev
next >
Wrap
Text File
|
1995-10-03
|
3KB
|
157 lines
#!/bin/ksh
# Do a cpio -p after checking for room on the destination
set -u
PATH=$PATH:/etc:/usr/bin
name=`id -nu`
if [ $name != root ]
then
echo You must be root to copy the files!
exit 1
fi
PWD=`pwd`
umask a=rwx
arg0=$0
DIR=`dirname $arg0`
if [ $DIR = "." ]
then
source=${PWD}
else
source=${DIR}
fi
progname=`basename $0`
if [[ $# -ne 1 ]]
then
echo "What is the destination directory? " >&2
read target
else
target=$1
fi
echo "Do you wish to copy the Japanese language files? [no]" >&2
read doj
if [ "$doj" = "Y" -o "$doj" = "YES" -o "$doj" = "Yes" -o "$doj" = "y" -o "$doj" = "yes" ]
then
doj=yes
else
doj=no
fi
echo "Do you wish to copy the Korean language files? [no]" >&2
read dok
if [ "$dok" = "Y" -o "$dok" = "YES" -o "$dok" = "Yes" -o "$dok" = "y" -o "$dok" = "yes" ]
then
dok=yes
else
dok=no
fi
echo "Do you wish to copy the Chinese language files? [no]" >&2
read doc
if [ "$doc" = "Y" -o "$doc" = "YES" -o "$doc" = "Yes" -o "$doc" = "y" -o "$doc" = "yes" ]
then
doc=yes
else
doc=no
fi
if [[ ! -d $source ]]
then
echo "$progname: $source is not a readable directory" >&2
exit 2
fi
if [[ -d $target ]] # It's already there
then
if [[ ! -w $target ]]
then
echo "$progname: $target is not writeable by you" >&2
exit 3
fi
else # Try making it; if it's a normal file this will fail
mkdir -p $target >/dev/null 2>&1
if [[ $? -ne 0 ]]
then
echo "$progname: cannot create target directory $target">&2
exit 4
fi
fi
echo "Calculating space needed..." # du is not terribly fast
needed=`du -s $source | cut -f1`
if [ "$doj" = "no" ]
then
neededj=`du -s $source/lib/PowerON-II/japanese | cut -f1`
let "needed=needed-neededj"
fi
if [ "$dok" = "no" ]
then
neededk=`du -s $source/lib/PowerON-II/korean | cut -f1`
let "needed=needed-neededk"
fi
if [ "$doc" = "no" ]
then
neededc=`du -s $source/lib/PowerON-II/chinese-t | cut -f1`
let "needed=needed-neededc"
fi
# Use devnm to resolve the destination drive, then df it. df output
# for NFS mounts includes an extra colon so don't key on it.
echo "Calculating space available..."
targetdev=`devnm $target | cut -d' ' -f1`
available=`df $targetdev | cut -d')' -f2 | awk '{print $2}'`
let "needed=needed/2"
let "available=available/2"
if [[ $needed -gt $available ]]
then
echo "$progname: not enough room to copy everything" >&2
echo " $needed Kbytes are needed but $available Kbytes are available." >&2
exit 5
fi
echo "This will take $needed K bytes. Do you wish to proceed? [yes]" >&2
read pro
if [ "$pro" = "Y" -o "$pro" = "YES" -o "$pro" = "Yes" -o "$pro" = "y" -o "$pro" = "yes" ]
then
pro=yes
else
pro=no
fi
echo "Copying..." # Don't go verbose so that error messages can be seen
cd $source
find ./* -path ./lib/PowerON-II/japanese -prune -o -path ./lib/PowerON-II/korean -prune -o -path ./lib/PowerON-II/chinese-t -prune -o -print | cpio -pudlm $target # no 'x', no device files needed
if [ "$doj" = "yes" ]
then
find ./lib/PowerON-II/japanese -print | cpio -pudlm $target # no 'x', no device files needed
fi
if [ "$dok" = "yes" ]
then
find ./lib/PowerON-II/korean -print | cpio -pudlm $target # no 'x', no device files needed
fi
if [ "$doc" = "yes" ]
then
find ./lib/PowerON-II/chinese-t -print | cpio -pudlm $target # no 'x', no device files needed
fi
echo "$progname: complete"
exit 0